### 测试1. pandas 读取 Excel 表格数据
# import pandas # pip install pandas openpyxl

# from tkinter import filedialog

# # 选择 命名模板  (Excel)
# print('请打开命名模板: (目前仅支持 .xls .xlsx)')
# inputScript = filedialog.askopenfilename(title='打开命名模板', filetypes=(('Microsoft Excel 工作表', '*.xls *.xlsx'),))
# print(inputScript, '\n')

# content = pandas.read_excel(inputScript)
# print(content['證書編號'])

### 测试2. 多线程模式
# import threading
# import time

# list = [0,0,0,0,0,0,0,0,0,0,0,0]

# class myThread(threading.Thread):
#     def __init__(self, threadId, name, count):
#         threading.Thread.__init__(self)
#         self.threadId = threadId
#         self.name = name
#         self.count = count
#     def run(self):
#         print('开始线程: ',self.name)
#         # 获得锁，成功获得锁定后返回 True
#         # 可选的timeout参数不填时将一直阻塞直到获得锁定
#         # 否则超时后将返回 False
#         # threadLock.acquire()
#         print_time(self.name, list.__len__(), self.count)
#         # 释放锁
#         # threadLock.release()
#     def __del__(self):
#         print(self.name, '线程结束')

# def print_time(tName, count, delay = 0.5):
#     while count:
#         time.sleep(delay)
#         list[count-1] += 1
#         print("[%s] %s 修改第 %d 个值, 修改后值为: %d" % (time.ctime(time.time()), tName, count, list[count-1]))
#         count -= 1

# threadLock = threading.Lock()
# threads = []
# # 创建新线程
# thread1 = myThread(1,"Thread-1",0.2)
# thread2 = myThread(2,"Thread-2",0.5)
# # 运行新线程
# thread1.start()
# thread2.start()
# # 添加线程到线程列表
# threads.append(thread1)
# threads.append(thread2)
# # 等待所有线程完成
# for t in threads:
#     t.join()
# print("主进程结束")

### 测试3. 格式化输出
PAGECOUNT = int(10)
cert_num = []
custom_name = input('输入自定义命名模板: 规则：字符串 + "#"表示插入数字 \n(若无规则请直接按下回车)')
ran = eval(input('请输入数字的开始序号: ') or '1')
# 统计 custom_name 数字占位符数量
num_bit = custom_name.count('#')
print('数字占位符为: ',num_bit)
# 根据用户规则进行生成命名
for i in range(ran, ran + PAGECOUNT):
    rename = custom_name.replace('#','')
    # 数字部分缺少位数则补 0
    for j in range(num_bit - len(str(i))):
        rename += '0'
    rename += str(i)
    print(rename)
# 如果没有输入自定义命名模板则直接使用纯数字序列命名
if not custom_name:
    for i in range(1, PAGECOUNT + 1):
        cert_num.append(i)
    print(cert_num)
else:
    for i in range(ran, ran + PAGECOUNT):
        rename = custom_name.replace('#','')
        # 数字部分缺少位数则补 0
        for j in range(num_bit - len(str(i))):
            rename += '0'
        rename += str(i)
        cert_num.append(rename)
    print(cert_num)